let DateUtil = {
    /**
     *获取日期的年月日时分秒，不传参时获取今天
     */
    getDateInfo(date) {
        if (!date)
            date = new Date();
        return {
            Y: date.getFullYear(),
            M: date.getMonth(),
            D: date.getDate(),
            H: date.getHours(),
            m: date.getMinutes(),
            s: date.getSeconds()
        }
    },
    /**
     * 将时分转为小数格式 9:30 -> 9.5
     */
    hm2num(hm) {
        let today = this.getDateInfo();
        let date = new Date(`${today.Y}/${today.M}/${today.D} ${hm}:00`);
        return date.getHours() + date.getMinutes() / 60;
    },
    /**
     * 获取日期的时分
     * @return number 如：9.5（9点半）
     */
    getHmByDate(date) {
        if (!date)
            date = new Date();
        return date.getHours() + date.getMinutes() / 60;
    },
    /**
     * 为日期添加n天
     * @param date
     */
    addDate(date, n) {
        date.setDate(date.getDate() + n);
        return date
    },
    /**
     * 是否同一周，一周从星期天开始
     */
    isSameWeek(old, now) {
        let oneDayTime = 1000 * 60 * 60 * 24;
        let old_count = parseInt(old.getTime() / oneDayTime);
        let now_other = parseInt(now.getTime() / oneDayTime);
        return parseInt((old_count + 5) / 7) === parseInt((now_other + 5) / 7);
    }
}
export default DateUtil
